etc: Use Popen instead of call to spawn processes
authorAlex Crichton <alex@alexcrichton.com>
Wed, 22 Jul 2015 21:33:52 +0000 (14:33 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 23 Jul 2015 05:53:09 +0000 (22:53 -0700)
I saw the usage of `call` locking up quite a bit when running this script on
Windows, and googling around on the internet seems to indicate that Popen should
be used instead of call to prevent this locking up, and it does indeed work!

src/etc/download.py

index 2a6636ccf83266c805033827d9d8610301119c1e..080fda9e29719e358209ab192b1975409706445b 100644 (file)
@@ -31,8 +31,19 @@ def unpack(tarball, dst, quiet=False):
             shutil.move(tp, fp)
     shutil.rmtree(os.path.join(dst, fname))
 
-def run(args):
-    print("running: " + ' '.join(args))
-    ret = subprocess.call(args)
-    if ret != 0:
-        raise Exception("failed to fetch url: " + url)
+def run(args, quiet=False):
+    if not quiet:
+        print("running: " + ' '.join(args))
+    sys.stdout.flush()
+    # Use Popen here instead of call() as it apparently allows powershell on
+    # Windows to not lock up waiting for input presumably.
+    ret = subprocess.Popen(args,
+                           stdin = subprocess.PIPE,
+                           stdout = subprocess.PIPE,
+                           stderr = subprocess.PIPE)
+    out, err = ret.communicate()
+    code = ret.wait()
+    if code != 0:
+        print("stdout: \n\n" + out)
+        print("stderr: \n\n" + err)
+        raise Exception("failed to fetch url")